package br.com.doclayer.service.fs;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;

import org.apache.commons.io.FileUtils;

import br.com.doclayer.ContentMetadata;
import br.com.doclayer.FolderMetadata;
import br.com.doclayer.ObjectMetadata;
import br.com.doclayer.fs.ContentFsImpl;
import br.com.doclayer.fs.FolderFsImpl;
import br.com.doclayer.service.DocService;

public class DocServiceFsImpl implements DocService {

  @Override
  public FolderMetadata createFolder(String parentFolderUuid,
      String newFolderName) {
    FolderMetadata folderMetadata = this.getFolderMetadata(parentFolderUuid);
    String newFolderUuid = UUID.randomUUID().toString();

    File newFolder = new File(folderMetadata.getPath() + "/" + newFolderName);
    if (!newFolder.exists()) {
      newFolder.mkdir();
    }

    return new FolderFsImpl(newFolder, newFolderUuid);
  }

  @Override
  public ContentMetadata addContent(File file, String... foldersUuid)
      throws IOException {
    FolderMetadata folderMetadata = this.getFolderMetadata(foldersUuid[0]);
    String newContentUuid = UUID.randomUUID().toString();
    File newContent = new File(folderMetadata.getPath(), file.getName());
    FileUtils.copyFile(file, newContent);

    return new ContentFsImpl(newContent, newContentUuid);
  }

  @Override
  public void removeObject(String pathOrUuid) {
    // TODO Auto-generated method stub

  }

  @Override
  public void removeObject(ObjectMetadata objectMetadata) {
    this.removeObject(objectMetadata.getUuid());
  }

  @Override
  public ObjectMetadata getObjectMetadata(String pathOrUuid) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public ContentMetadata getContentMetadata(String pathOrUuid) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public FolderMetadata getFolderMetadata(String pathOrUuid) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public List<ObjectMetadata> getFolderChildren(String uuid) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public long getFolderSize(String pathOrUuid) {
    // TODO Auto-generated method stub
    return 0;
  }

  @Override
  public InputStream getContentStream(String uuid) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public InputStream getContentStream(ContentMetadata contentMetadata) {
    // TODO Auto-generated method stub
    return null;
  }

}
